/* eslint-disable */
/**
 * Created by GYL on 2018/8/24
 */
import React, { Component } from 'react';
import styles from '../EventPosting.less';
import { Collapse, Icon, Select, Input, Tooltip, Form, Row, Col, TreeSelect, Tag, message, Tree,Empty } from 'antd';
import Container from "../../../components/common/Container";
import PublicService from "../../../services/PublicService";
import config from '../../../config';
import Util from '../../../utils/Util';
import request from '../../../utils/request';
import MyTable from "../../../components/common/MyTable";
import MyModal from '../../../components/common/MyModal';
import JSGanttComponent from 'react-jsgantt';
class WBS_warp extends Component {



  constructor(props) {
    super(props);

    const vAdditionalHeaders = {
      zxh: { title: '序号' },
      zposid: { title: 'WBS编号' },
      // zxzpost1h: { title: 'WBS名称' },
      ztbcb: { title: '投标成本' },
      zxmys: { title: '项目预算' },
      zwqcb: { title: '未清成本' },
      zyfscb: { title: '已发生成本' },

    };

    this.state = {
      data: [],//甘特图
      spinning: false
    }






    this.editorOptions = {
      vCaptionType: 'Complete',  // Set to Show Caption : None,Caption,Resource,Duration,Complete,控制右边图形结尾显示
      vQuarterColWidth: 36,
      vDateTaskDisplayFormat: ' yyyy-mm-dd', // Shown in tool tip box
      vDayMajorDateDisplayFormat: ' yyyy-mm-dd', // Set format to display dates in the "Major" header of the "Day" view
      // vWeekMinorDateDisplayFormat: 'dd 日', // Set format to display dates in the "Minor" header of the "Week" view
      vLang: 0,
      vUseSingleCell: 0,
      vShowRes: 0,
      vShowCost: 0,
      vShowComp: 0,
      vShowDur: 0,
      vShowStartDate: 0,
      vShowEndDate: 0,
      vShowPlanStartDate: 0,
      vShowPlanEndDate: 0,
      vShowTaskInfoEndDate: 0,
      vShowTaskInfoLink: parseInt(this.vShowTaskInfoLink, 10), // Show link in tool tip (0/1)
      // Show/Hide the date for the last day of the week in header for daily view (1/0)
      // vTaskInfo: 0,
      vAdditionalHeaders: vAdditionalHeaders,//左边表格头部
      vEvents: {
        taskname: 0,//点击触发
        res: 0,
        dur: 0,
        comp: 0,
        start: 0,
        end: 0,
        planstart: 0,
        planend: 0,
        cost: 0
      },
      vEventsChange: {
        taskname: this.editValue.bind(this, this.state.data),//编辑触发
        res: this.editValue.bind(this, this.state.data),
        dur: this.editValue.bind(this, this.state.data),
        comp: this.editValue.bind(this, this.state.data),
        start: this.editValue.bind(this, this.state.data),
        end: this.editValue.bind(this, this.state.data),
        planstart: this.editValue.bind(this, this.state.data),
        planend: this.editValue.bind(this, this.state.data),
        cost: this.editValue.bind(this, this.state.data)
      },
      vResources: [

      ],
      // vEventClickRow: console.log,
      vTooltipDelay: 0,
      vDebug: false,
      vEditable: false,//是否可以编辑
      vUseSort: false,
      vFormatArr: ['Day', 'Week', 'Month'],//切换控制日期选择,日,周,月
    };
  }

  componentDidMount() {

    // this.onSubmit()

    //获取甘特图数据
    // request({
    //   url: '/pm-web/projectmanage/progress/getWbsData',
    //   method: 'POST',
    //   data: { projectId: this.props.id }
    // }).then(data => {
    //   if (data.rc === 0) {
    //     this.setState({
    //       data: data.ret.list
    //     })
    //   }
    // })

  }


  getWbsData = () => {
    request({
      url: '/pm-web/projectmanage/progress/getWbsData',
      method: 'POST',
      data: { projectId: this.props.id }
    }).then(data => {
      if (data.rc === 0) {
        this.setState({
          data: data.ret.list
        })
      }
    })
  }

  editValue(list, task, event, cell, column) {
    // tslint:disable-next-line:triple-equals
    const found = list.find(item => item.pID == task.getOriginalID());
    if (!found) {
      return;
    } else {
      found[column] = event ? event.target.value : '';
    }
    // console.log(found);
  }

  render() {
    let t = this
    let width = document.body.clientWidth;
    const height = document.body.clientHeight;
    let containerHeight = '80vh';
    let tableHeight = 310;
    if (width > 1367) {
      tableHeight = 380;
      containerHeight = '83vh';
    }


    return (
      <div className={styles.WBS_warp}>
      {
        this.props.WBSdata.length>0?<JSGanttComponent data={this.props.WBSdata} options={this.editorOptions} />:<Empty />
      }
        
      </div>
    );


  }


}
export default WBS_warp;

